<%@page import="user.Item"%>
<%@page import="java.net.URLEncoder"%>
<%@ page language="java" import="java.util.*"
	contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="user.Uers"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<%
	
%>
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

</head>

<body>
	<%-- 

<h1>普通方法使用javabean </h1><hr>
<% 
	Uers s = new Uers();
	s.setStrname("huang");
	s.setAge(23);
	
%>

	用户名：<%=s.getStrname() %><br>
	年龄：<%=s.getAge() %><br>
	<hr>
	<h1>使用jsp动作标签使用javabean</h1>
	<hr>
	<jsp:useBean id="myuser" class="user.Uers" scope="page"></jsp:useBean>
	<jsp:setProperty property="*" name="myuser"/>
	姓名：<%=myuser.getStrname() %><br>
	年龄：<%=myuser.getAge() %>
	 --%>
	<h1>登录成功！</h1>
	<hr>
	<%
		request.setCharacterEncoding("utf-8");
		String username = "";
		String password = "";
		if (request.getParameter("username")!=null
				&& request.getParameter("password")!=null) {
			username = request.getParameter("username").toString();
			password = request.getParameter("password").toString();
		}
		Item items = new Item();
		boolean b = true;
		try {
			b = items.loginUers(username, password);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		if (b) {
	%>

	用户名：<%=username%><br>
	密码：<%=password%><br>

	<%
		} else {
			String msg = "账户或名密码错误！！";
			msg = URLEncoder.encode(msg, "utf-8");
			response.sendRedirect("login.jsp?msg=" + msg);
		}
	%>
	<a href="user.jsp" target="_blank">查看个人信息</a>
	<%--
		request.setCharacterEncoding("UTF-8");
		
		
		
		String[] isUseCookie = request.getParameterValues("isUseCookie");
		if (isUseCookie != null && isUseCookie.length > 0) {
			String username = URLEncoder.encode(request.getParameter("username"),"utf-8");
			String password =  URLEncoder.encode(request.getParameter("password"),"utf-8");
			Cookie cookieusername = new Cookie("username", username);
			Cookie cookiepassword = new Cookie("password", password);
			cookieusername.setMaxAge(600);
			cookiepassword.setMaxAge(600);
			response.addCookie(cookieusername);
			response.addCookie(cookiepassword);
		} else {
			Cookie[] cookies = request.getCookies();
			if (cookies != null && cookies.length > 0) {
				for (Cookie c : cookies) {
					if (c.getName().equals("username")
							|| c.getName().equals("password")) {
						c.setMaxAge(0);
						response.addCookie(c);
					}
				}
			}
		}
	--%>
</body>
</html>
